package com.chris.libs.base.x.mvpp.application;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.ViewModelStoreOwner;

/**
 * @author Chris chan
 * Create on： 2025/9/13 8:37
 * Use for: 全局ViewModel仓库所有者
 * Explain:
 */
public class ApplicationViewModelStoreOwner implements ViewModelStoreOwner {
    private static ViewModelStore viewModelStore = new ViewModelStore();
    private static ApplicationViewModelStoreOwner instance;

    private ApplicationViewModelStoreOwner() {

    }

    // 单例
    public static ApplicationViewModelStoreOwner getInstance() {
        if (null == instance) {
            synchronized (ApplicationViewModelStoreOwner.class) {
                if (null == instance) {
                    instance = new ApplicationViewModelStoreOwner();
                }
            }
        }
        return instance;
    }

    /**
     * Returns owned {@link ViewModelStore}
     *
     * @return a {@code ViewModelStore}
     */
    @NonNull
    @Override
    public ViewModelStore getViewModelStore() {
        return viewModelStore;
    }
}
